10 edge(int t
, int w
, int l
) : to(t
), weight(w
), lift(l
) {}
11 bool operator < (const edge
&that
) const{
12 return weight
> that
.weight
;
18 while (cin
>> n
>> k
){
20 vector
<int> floors
[n
]; //List of floors visited by elevator i-th
22 for (int i
=0; i
<n
; ++i
){
27 for (int i
=0; i
<n
; ++i
){
29 stringstream
ss(line
);
32 floors
[i
].push_back(x
);
34 floors
[i
].push_back(y
);
35 g
[x
].push_back(edge(y
, (y
-x
)*t
[i
], i
));
36 g
[y
].push_back(edge(x
, (y
-x
)*t
[i
], i
));
42 for (int i
=0; i
<100; ++i
) for (int j
=0; j
<n
; ++j
) d
[i
][j
] = INT_MAX
;
44 priority_queue
<edge
> q
;
46 for (int j
=0; j
<n
; ++j
){
47 if (floors
[j
].front() == 0){
48 //cout << "Starting at elevator " << j << " ends at floor " << floors[j].back() << endl;
49 d
[0][j
] = floors
[j
].back() * t
[j
];
50 q
.push(edge(0, d
[0][j
], j
));
60 edge top
= q
.top(); q
.pop();
62 if (top
.to
== k
) break;
63 if (d
[top
.to
][top
.lift
] < top
.weight
) continue;
65 for (int i
=0; i
<g
[top
.to
].size(); ++i
){
66 edge u
= g
[top
.to
][i
];
69 if ((tmp
= top
.weight
+ u
.weight
+ (top
.lift
!= u
.lift
?(max(top
.to
- floors
[u
.lift
].front(), floors
[u
.lift
].back() - top
.to
)*t
[u
.lift
]+5):0)) < d
[u
.to
][u
.lift
]){
70 d
[u
.to
][u
.lift
] = tmp
;
71 q
.push(edge(u
.to
, tmp
, u
.lift
));
75 int a
= *min_element(d
[k
], d
[k
]+n
);
79 cout
<< "IMPOSSIBLE" << endl
;